from pathlib import Path
from decord.ndarray import cpu
from decord.video_reader import VideoReader


def get_vr_obj(path: Path):
    vr = VideoReader(path.as_posix(), ctx=cpu(0))
    fps = vr.get_avg_fps()
    total_frame = vr._num_frame
    return vr, total_frame, fps


def get_video_info(path: Path):
    vr, total_frame, fps = get_vr_obj(path)
    frame = vr[0].asnumpy()
    wide, high = frame.shape[1], frame.shape[0]
    total_time = round(total_frame / fps, 3)
    return wide, high, total_time

